import 'package:flutter/material.dart';

import '../../common/index.dart';

import '../../tools/index.dart';
import '../vm/eg_vm.dart';
import '../widgets/index.dart';

class EgStateListV extends StatefulWidget {
  const EgStateListV({super.key});
  @override
  State<StatefulWidget> createState() {
    return EgStateListVState();
  }
}

class EgStateListVState extends BaseListState<EgStateListV> {
  // --------- 公开属性  --------- //

  // --------- 私有属性  --------- //
  EgVm vm = EgVm();

  @override
  bool get safeAreaTop => false;

  @override
  bool get isShowAppBar => false;

  // --------- 生命周期  --------- //
  @override
  void initState() {
    super.initState();
    // 请求网络数据 type 1 下拉刷新 2 上拉加载 3 初始化加载默认动画
    getNetWorkData(type: 3);
  }

  // --------- 构建UI  --------- //

  @override
  Widget createListView(BuildContext context) {
    Widget body = EgListWidget(
      itemList: vm.itemList,
    );
    return body;
  }

  //  item构建
  createItemBuilder(BuildContext context, int index) {
    Widget body = ItemLessWidget(item: vm.itemList[index]);
    return body;
  }

  //  分割线构建
  createSeparatorBuilder(BuildContext context, int index) {
    Widget body = Gaps.vGap10;
    return body;
  }

  // --------- 数据处理  --------- //

  // 请求网络数据
  @override
  getNetWorkData({int? type, Map<String, dynamic>? info}) async {
    await vm.configListData(page: page, isShowLoad: type == 3);
    configSetState(() {
      pageState = vm.pageState;
    });
    // 结束刷新状态
    endRefresh(type: type!, state: pageState);
  }

  // --------- 触发事件  --------- //
  @override
  tapPlaceHoldWidgetMethod({
    required CommonPlaceHoldType placeHoldType,
  }) {
    getNetWorkData(type: 3);
  }
}
